﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.IndexObject
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;

namespace Microsoft.InfoCards
{
  internal class IndexObject
  {
    private object[] m_objects;
    private byte[] m_compiledForm;

    public IndexObject(object[] objects)
    {
      this.m_objects = objects;
    }

    public IndexObject(byte[] compiledForm)
    {
      this.m_compiledForm = compiledForm;
    }

    public bool IsCompiled
    {
      get
      {
        return null != this.m_compiledForm;
      }
    }

    public bool CanCompile
    {
      get
      {
        return null != this.m_objects;
      }
    }

    public byte[] CompiledForm
    {
      get
      {
        return this.m_compiledForm;
      }
    }

    public object[] ObjectList
    {
      get
      {
        return this.m_objects;
      }
    }

    internal void Compile(SecondaryIndexDefinition indexDef)
    {
      if (!this.CanCompile)
        throw InfoCardTrace.ThrowHelperError((Exception) new InvalidOperationException(SR.GetString("StoreIndexObjectCanNotBeCompiled")));
      byte[] numArray1 = new byte[60];
      int destinationIndex = 0;
      for (int index = 0; index < this.m_objects.Length; ++index)
      {
        if (!indexDef.Canonicalizer.CanCanonicalize(this.m_objects[index]))
          throw InfoCardTrace.ThrowHelperError((Exception) new InvalidOperationException(SR.GetString("StoreIndexObjectCanNotBeCanonicalized", (object) this.m_objects[index].GetType())));
        byte[] numArray2 = indexDef.Canonicalizer.Canonicalize(this.m_objects[index]);
        if (numArray2.Length + destinationIndex > numArray1.Length)
          throw InfoCardTrace.ThrowHelperError((Exception) new InvalidOperationException(SR.GetString("StoreIndexObjectBufferOverflow", (object) indexDef.Name)));
        Array.Copy((Array) numArray2, 0, (Array) numArray1, destinationIndex, numArray2.Length);
        destinationIndex += numArray2.Length;
      }
      this.m_compiledForm = numArray1;
    }
  }
}
